package com.studentsystem.service.impl;

import com.studentsystem.dao.StudentDao;
import com.studentsystem.dataobject.StudentDO;
import com.studentsystem.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Student)表服务实现类
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StudentDO queryById(Long id) {
        return this.studentDao.queryById(id);
    }

    @Override
    public StudentDO queryByUsername(String username) {
        return this.studentDao.queryByUsername(username);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<StudentDO> queryAllByLimit(int offset, int limit) {
        return this.studentDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<StudentDO> queryByClasssAndGrade(String classs, Integer grade) {
        StudentDO studentDO = new StudentDO();
        studentDO.setClasss(classs);
        studentDO.setStartStudy(grade);
        return this.studentDao.queryAll(studentDO);
    }

    @Override
    public List<StudentDO> queryAll() {
        return this.studentDao.queryAll(new StudentDO());
    }

    @Override
    public List<StudentDO> getStudentsByParam(String param) {
        return this.studentDao.getStudentsByParam(param);
    }

    /**
     * 新增数据
     *
     * @param studentDO 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insert(StudentDO studentDO) {
        return this.studentDao.insert(studentDO) > 0;
    }

    /**
     * 修改数据
     *
     * @param studentDO 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean update(StudentDO studentDO) {
        return this.studentDao.update(studentDO) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.studentDao.deleteById(id) > 0;
    }
}